//
//  PeronalInfoViewController.m
//  atXiaoGeBClient
//
//  Created by Linyu Niu on 19/04/2018.
//  Copyright © 2018 Linyu Niu. All rights reserved.
//

#import "PersonalInfoViewController.h"

@interface PersonalInfoViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * infoTableView;
    NSArray * infoTableList;
}

@end

@implementation PersonalInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString * path = [[NSBundle mainBundle]pathForResource:@"PersonalInfos" ofType:@"plist"];
    infoTableList = [[NSArray alloc]initWithContentsOfFile:path];
    
    __weak PersonalInfoViewController * weakSelf = self;
    UIView * navView = [[CTMediator sharedInstance] navgationHeadViewInTargetView:self.view params:[NSDictionary dictionaryWithObjectsAndKeys:@"个人信息",@"title", nil] leftAction:^(UIButton * sender){
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } rightAction:nil];
    infoTableView = [self addTableViewInView:self.view frame:CGRectMake(0, navView.frame.origin.y + navView.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - (navView.frame.origin.y + navView.frame.size.height)) delegateAndDataSource:self];
    infoTableView.backgroundColor = [UIColor colorWithRed:233.0 / 255.0 green:233.0 / 255.0 blue:233.0 / 255.0 alpha:1.0];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ElementTableViewCell * cell = (ElementTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.cellHeight;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ElementTableViewCell * cell = [[ElementTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    NSArray * list = [infoTableList objectAtIndex:[indexPath section]];
    NSDictionary * dic = [list objectAtIndex:[indexPath row]];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.textLabel.textColor = UIColorFromRGB(0x333333);
    cell.textLabel.text = [dic objectForKey:@"name"];
    if ([indexPath section] == 0) {
        cell.cellHeight = 80;
        
        UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(tableView.frame.size.width - 30 - 50, (cell.cellHeight - 50) / 2, 50, 50)];
        imgView.layer.cornerRadius = imgView.frame.size.height / 2;
        imgView.layer.masksToBounds = YES;
        imgView.backgroundColor = [UIColor blueColor];
        [cell addSubview:imgView];
    }else{
        cell.cellHeight = 60;
    }
    NSInteger numberRow = [tableView numberOfRowsInSection:[indexPath section]];
    if (numberRow > 1 && [indexPath row] < numberRow - 1) {
        UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, cell.cellHeight - 1.0, tableView.frame.size.width , 1.0)];
        lineView.backgroundColor = [UIColor colorWithRed:233.0 / 255.0 green:233.0 / 255.0 blue:233.0 / 255.0 alpha:1.0];
        [cell addSubview:lineView];
    }
    return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray * list = [infoTableList objectAtIndex:section];
    return [list count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [infoTableList count];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 15)];
    return v;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}

@end
